﻿@using DCMS.Web.Extensions;
@using DCMS.Web.Framework.UI;
@using DCMS.ViewModel.Models.WareHouses;

@model StockProductModel

<input asp-for="ProductId" type="hidden" />
<input asp-for="CategoryId" type="hidden" />

<div class="row">
    <div class="col-md-12">
        @if (Model.CategoryId == 0)
        {
            <table class="table table-striped table-hover" id="AsyncStockInOutRecords"></table>
        }
        else
        {
            <table class="table table-striped table-hover" id="AsyncStockFlows"></table>
        }
        <div class="clearfix"></div>
    </div>
</div>

<script type="text/javascript">

    $(function () {

        $('body').on('shown.bs.modal', function () {
            $("#AsyncStockInOutRecords").bootstrapTable('refresh');
        });

         //商品列表
        $("#AsyncStockInOutRecords").bootstrapTable({
            url: "/StockReport/AsyncStockInOutRecords",
            method: 'get',
            striped: true,
            cache: false,
            pagination: true,
            queryParams: function (params)
            {
                var temp =
                {
                    store: null,
                    productId: @Model.ProductId,
                    pageSize: params.limit,
                    pageIndex: (params.offset / params.limit)
                };
                return temp;
            },
            sidePagination: "server",
            idField: 'Id',
            dataField: "rows",
            totalField: "total",
            pageNumber: 1,
            pageSize: 20,
            search: false,
            strictSearch: true,
            showRefresh: false,
            clickToSelect: false,
            uniqueId: "Id",
            showToggle: false,
            cardView: false,
            detailView: false,
            columns: [
                { checkbox: true },
                { field: 'Id', visible: false },
                { field: 'BillId', title: '单据标识', align: 'center' },
                { field: 'BillCode', title: '单据编号', align: 'center' },
                { field: 'BillType', title: '单据类型', align: 'center' },
                { field: 'Quantity', title: '数量', align: 'center' },
                {
                    field: 'Direction',
                    title: '方向',
                    align: 'center',
                    formatter: function (value, row, index)
                    {
                        if (value == 1)
                            return "入库";
                        else
                            return "出库";
                    }
                },
                { field: 'OutWareHouseId', title: '出库', align: 'center' },
                { field: 'InWareHouseId', title: '入库', align: 'center' },
                { field: 'CreatedOnUtc', title: '时间', align: 'center' }
            ],
            onPageChange: function (number, size) {
                m_pagerow = (number - 1) * size;
            },
            onLoadSuccess: function (data) {
                //console.log('load');
            }
        });


        //商品列表
        $("#AsyncStockFlows").bootstrapTable({
            url: "/StockReport/AsyncStockFlows",
            method: 'get',
            striped: true,
            cache: false,
            pagination: true,
            queryParams: function (params) {
                var temp =
                {
                    store: null,
                    productId: @Model.ProductId,
                    pageSize: params.limit,
                    pageIndex: (params.offset / params.limit)
                };
                return temp;
            },
            sidePagination: "server",
            idField: 'Id',
            dataField: "rows",
            totalField: "total",
            pageNumber: 1,
            pageSize: 10,
            search: false,
            strictSearch: true,
            showRefresh: false,
            clickToSelect: false,
            uniqueId: "Id",
            showToggle: false,
            cardView: false,
            detailView: false,
            //{"Id":44191,"StoreId":438,"StockId":11009,"ProductId":1671743,"ProductName":"1.5L娃哈哈刺C赢水果饮品","ProductCode":"","UnitId":63050,"SmallUnitId":29267,"BigUnitId":63050,"Quantity":2668,"UsableQuantityBefor":0,"UsableQuantityAfter":2668,"UsableQuantityChange":2668,"CurrentQuantityBefor":0,"CurrentQuantityAfter":2668,"CurrentQuantityChange":2668,"OrderQuantityBefor":0,"OrderQuantityAfter":0,"OrderQuantityChange":0,"LockQuantityBefor":0,"LockQuantityAfter":0,"LockQuantityChange":0,"ChangeType":2,"CreaterId":5521,"CreateTime":"2021-07-03T09:20:34.441","TimeStamp":"2021-07-03T09:20:34","IsExpiredGood":false
            columns: [
                { checkbox: true },
                { field: 'Id', visible: false },
                { field: 'StockId', title: '库存标识', align: 'center' },
                { field: 'ProductId', title: '商品编号', align: 'center' },
                { field: 'ProductName', title: '商品名称', align: 'center' },
                { field: 'UnitId', title: '单位', align: 'center' },
                { field: 'SmallUnitId', title: '小单位', align: 'center' },
                { field: 'BigUnitId', title: '大单位', align: 'center' },
                { field: 'Quantity', title: '数量', align: 'center' },

                { field: 'UsableQuantityBefor', title: '可用变化前', align: 'center' },
                { field: 'UsableQuantityAfter', title: '可用变化后', align: 'center' },
                { field: 'UsableQuantityChange', title: '可用变化量', align: 'center' },

                { field: 'CurrentQuantityBefor', title: '现货变化前', align: 'center' },
                { field: 'CurrentQuantityAfter', title: '现货变化后', align: 'center' },
                { field: 'CurrentQuantityChange', title: '现货变化量', align: 'center' },

                { field: 'OrderQuantityBefor', title: '预占变化前', align: 'center' },
                { field: 'OrderQuantityAfter', title: '预占变化后', align: 'center' },
                { field: 'OrderQuantityChange', title: '预占变化量', align: 'center' },

                { field: 'CreateTime', title: '时间', align: 'center' }

            ],
            onPageChange: function (number, size) {
                m_pagerow = (number - 1) * size;
            },
            onLoadSuccess: function (data) {
                //console.log('load');
            }
        });
    });
</script>